"""
# -*- coding: utf-8 -*-
# @Time    : 2023/5/24 15:14
# @Author  : 王摇摆
# @FileName: Visual.py
# @Software: PyCharm
# @Blog    ：https://blog.csdn.net/weixin_44943389?type=blog
"""
import numpy as np
import matplotlib.pyplot as plt
from matplotlib.colors import LinearSegmentedColormap
from GBDT.BinaryClassification.Data import X, y
from GBDT.BinaryClassification.Train import clf  # 从实例中引入分类器
from matplotlib.font_manager import FontProperties
import warnings
warnings.filterwarnings('ignore')

# 指定中文字体文件的路径
font_path = 'C:\Windows\Fonts\simkai.ttf'
# 加载中文字体
font = FontProperties(fname=font_path)

fig, ax = plt.subplots()
ax.set_facecolor('#f8f9fa')

x_min, x_max = X[:, 0].min() - .5, X[:, 0].max() + .5
y_min, y_max = X[:, 1].min() - .5, X[:, 1].max() + .5
xx, yy = np.meshgrid(np.arange(x_min, x_max, .05), np.arange(y_min, y_max, .05))
Z = clf.predict(np.c_[xx.ravel(), yy.ravel()])
Z = Z.reshape(xx.shape)
clist = ['#ffadad', '#8ecae6']
newcmp = LinearSegmentedColormap.from_list('point_color', clist)
plt.pcolormesh(xx, yy, Z, cmap=newcmp)
plt.xlim(xx.min(), xx.max())
plt.ylim(yy.min(), yy.max())

x1 = X[y == -1][:, 0]
y1 = X[y == -1][:, 1]
x2 = X[y == 1][:, 0]
y2 = X[y == 1][:, 1]
p1 = plt.scatter(x1, y1, c='#e63946', marker='o', s=20)
p2 = plt.scatter(x2, y2, c='#457b9d', marker='x', s=20)

ax.set_title('梯度提升树二分类', color='#264653', font=font, fontsize=16)
ax.set_xlabel('X1', color='#264653')
ax.set_ylabel('X2', color='#264653')
ax.tick_params(labelcolor='#264653')
plt.legend([p1, p2], ["-EXP1", "EXP1"], loc="upper left")
print('GBDT二分类决策树已预测完毕！')
plt.show()
